﻿<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <link rel="Shortcut Icon" href="../images/aecc.ico" type="image/x-icon" />
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <link rel="stylesheet" href="../StaticFiles/element-ui/element-ui.css">
  <link rel="stylesheet" href="../StaticFiles/nprogress/nprogress.min.css">
  <link rel="stylesheet" href="../styles/vue-page-common.css">
  <link rel="stylesheet" href="../styles/table-transparent.css">
  <script src="../Scripts/vue.min.js"></script>
  <script src="../StaticFiles/element-ui/element-ui.js"></script>
  <script src="../Scripts/axios.min.js"></script>
  <script src="../StaticFiles/nprogress/nprogress.min.js"></script>
  <script src="../Scripts/crypto-js.js"></script>
  <script src="../Scripts/secret.js"></script>
  <script src="../Scripts/dayjs.min.js"></script>
  <script src="../Scripts/axios.config.js"></script>
  <script src="../Scripts/datav.min.vue.js"></script>
  <script src="../Scripts/lodash.min.js"></script>
  <title>批次停滞信息看板</title>
  <style>
    html {
      background-image: url(../images/bg.jpg);
      color: #fff;
    }

    .el-card {
      background-color: transparent;
      border: none;
      border: 1px dashed #1E9FFF;
    }

    .el-card__header {
      border: none;
      padding: 5px 20px;
    }

    .el-card__body {
      padding: 10px;
    }

    .card-title {
      color: #fff;
      font-size: 20px;
      display: flex;
      align-items: center;
      justify-content: center;
      font-weight: bold;
      background-color: transparent;
    }

    .header-title {
      font-size: 24px !important;
    }

    .el-form-item__label {
      color: #fff;
    }

    .el-table__header {
      color: red;
    }
  </style>
</head>

<body>
  <div id="app" v-cloak>
    <div style="padding:0 5px;">
      <!-- 看板标题组件 -->
      <vue2-board-header :title="'批次停滞信息看板'"></vue2-board-header>
      <!-- 查询条件区 -->
      <el-form :inline="true" :model="queryInfo" ref="queryInfoRef" :rules="rules" :label-position="'left'"
        style="margin:5px 0 0 5px;">
        <el-form-item label="分厂:">
          <el-select v-model="queryInfo.factoryid" placeholder="请选择分厂" filterable clearable>
            <el-option v-for="f in factoryList" :key="f.factoryid" :label="f.factoryname" :value="f.factoryid">
            </el-option>
          </el-select>
        </el-form-item>

        <el-form-item label="机型:">
          <el-select v-model="queryInfo.productfamilyname" placeholder="请选择机型" filterable clearable>
            <el-option v-for="f in productfamilyList" :key="f.productfamilyid" :label="f.productfamilyname"
              :value="f.productfamilyname">
            </el-option>
          </el-select>
        </el-form-item>

        <el-form-item prop='mfgordername' label="订单号:">
          <el-autocomplete v-model.trim="queryInfo.mfgordername" placeholder="请输入订单号" :trigger-on-focus="false"
            style="width:200px;" :fetch-suggestions="searchMfgorderAsync" :value-key="'mfgordername'" :debounce="500">
          </el-autocomplete>
        </el-form-item>

        <el-form-item prop='productname' label="零件图号:">
          <el-autocomplete v-model.trim="queryInfo.productname" placeholder="请输入零件图号" :trigger-on-focus="false"
            style="width:300px;" :fetch-suggestions="searchProductAsync" :value-key="'productname'" :debounce="500">
          </el-autocomplete>
        </el-form-item>

        <el-form-item prop='containername' label="流水卡号:">
          <el-autocomplete v-model.trim="queryInfo.containername" placeholder="请输入流水卡号" :trigger-on-focus="false"
            style="width:400px;" :fetch-suggestions="searchContainerAsync" :value-key="'containername'" :debounce="500">
          </el-autocomplete>
        </el-form-item>

        <el-form-item label="开卡时间:">
          <el-date-picker v-model="queryInfo.startdate" type="daterange" range-separator="至" value-format="yyyy-MM-dd"
            start-placeholder="开始日期" end-placeholder="结束日期" :picker-options="pickerOptions"></el-date-picker>
        </el-form-item>

        <el-form-item label="停滞时间:" prop="interval">
          <el-input-number v-model="queryInfo.interval" :min="1" :step="1" step-strictly>
          </el-input-number>
        </el-form-item>

        <el-form-item>
          <el-button type="primary" icon="el-icon-search" size="small" @click="searchData" :loading="loading">查询
          </el-button>
          <el-button type="primary" icon="el-icon-download" size="small" @click="exportData">导出</el-button>
        </el-form-item>
      </el-form>

      <el-row>
        <el-col :span="12">
          <dv-border-box-11 :title="factoryChartTitle" ref="factoryChart">
            <div style="height: 260px;padding-top: 40px;" id="factoryChart"></div>
          </dv-border-box-11>
        </el-col>
        <el-col :span="12">
          <dv-border-box-11 :title="productfamilyChart" ref="productfamilyChart">
            <div style="height: 260px;padding-top: 40px;" id="productfamilyChart"></div>
          </dv-border-box-11>
        </el-col>
      </el-row>

      <dv-border-box-11 title="停滞零件明细" ref="datagrid">
        <div id="gridWrapper" style="padding: 30px;padding-top:60px;padding-bottom:10px;">
          <div id="datagrid">
            <el-table v-loading="loading" v-loading.fullscreen.lock="loading" :element-loading-text="loadingText"
              element-loading-background="rgba(0,0,0,0.8)" :data="dataList" stripe border>
              <el-table-column type="index" width="50"></el-table-column>
              <el-table-column label="分厂" prop="factoryname" width="120" show-overflow-tooltip></el-table-column>
              <el-table-column label="订单号" prop="mfgordername" width="120" show-overflow-tooltip></el-table-column>
              <el-table-column label="机型" prop="familylistnames" width="100" show-overflow-tooltip>
              </el-table-column>
              <el-table-column label="零件图号" prop="productname" width="120" show-overflow-tooltip></el-table-column>
              <el-table-column label="零件名称" prop="productdescription" width="100" show-overflow-tooltip>
              </el-table-column>
              <el-table-column label="流水卡号" prop="containername" show-overflow-tooltip>
              </el-table-column>
              <el-table-column label="数量" prop="qty" width="60" show-overflow-tooltip></el-table-column>
              <el-table-column label="当前工序" prop="workflowstepname" width="100" show-overflow-tooltip>
              </el-table-column>
              <el-table-column label="主制工区" prop="fromworkcentername" width="100" show-overflow-tooltip>
              </el-table-column>
              <el-table-column label="计划员" prop="fullname" width="70" show-overflow-tooltip></el-table-column>
              <el-table-column label="开卡时间" prop="originalstartdate" width="100" :formatter="splitDate">
              </el-table-column>
              <el-table-column label="当前工序开始时间" prop="lastactivitydate" width="140" :formatter="splitDate">
              </el-table-column>
              <el-table-column label="停滞时间" prop="remaindays" width="100">
                <template slot-scope="scope">
                  <div v-if="scope.row.remaindays > 0" style="color:red;">
                    <el-popover placement="top-start" title="" width="200" trigger="hover" content="\n ">
                      <i class="el-icon-info" slot="reference"></i>
                      <span>停滞时间 = 系统当前时间 - 当前工序开始时间</span>
                    </el-popover>
                    {{scope.row.remaindays}} 天
                  </div>
                  <div v-else>0</div>
                </template>
              </el-table-column>
            </el-table>
            <el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange"
              :current-page="queryInfo.currentPage" :page-sizes="[10,18,50,100]" :page-size="queryInfo.pageSize"
              layout="prev,pager,next,jumper,sizes,total" :total="total">
            </el-pagination>
            <el-backtop></el-backtop>
          </div>
        </div>
      </dv-border-box-11>

      <!-- 各分厂停滞零件统计--明细对话框 -->
      <el-dialog :title="factoryChartDetail.title" :width="'95%'" :top="'10px'"
        :visible.sync="factoryChartDetail.dialogVisiable">
        <el-table v-loading="loading" v-loading.fullscreen.lock="loading" :element-loading-text="loadingText"
          element-loading-background="rgba(0,0,0,0.8)" :data="factoryChartDetail.dataList" stripe border>
          <el-table-column type="index" width="40px"></el-table-column>
          <el-table-column label="分厂" prop="factoryname" width="120" show-overflow-tooltip></el-table-column>
          <el-table-column label="订单号" prop="mfgordername" width="120" show-overflow-tooltip></el-table-column>
          <el-table-column label="机型" prop="familylistnames" width="100" show-overflow-tooltip>
          </el-table-column>
          <el-table-column label="零件图号" prop="productname" width="120" show-overflow-tooltip></el-table-column>
          <el-table-column label="零件名称" prop="productdescription" width="100" show-overflow-tooltip>
          </el-table-column>
          <el-table-column label="流水卡号" prop="containername" show-overflow-tooltip>
          </el-table-column>
          <el-table-column label="数量" prop="qty" width="60" show-overflow-tooltip></el-table-column>
          <el-table-column label="当前工序" prop="workflowstepname" width="100" show-overflow-tooltip>
          </el-table-column>
          <el-table-column label="主制工区" prop="fromworkcentername" width="100" show-overflow-tooltip>
          </el-table-column>
          <el-table-column label="计划员" prop="fullname" width="70" show-overflow-tooltip></el-table-column>
          <el-table-column label="开卡时间" prop="originalstartdate" width="100" :formatter="splitDate"></el-table-column>
          <el-table-column label="当前工序开始时间" prop="lastactivitydate" width="140" :formatter="splitDate">
          </el-table-column>
          <el-table-column label="停滞时间" prop="remaindays" width="100">
            <template slot-scope="scope">
              <div v-if="scope.row.remaindays > 0" style="color:red;">
                <el-popover placement="top-start" title="" width="200" trigger="hover" content="\n ">
                  <i class="el-icon-info" slot="reference"></i>
                  <span>停滞时间 = 系统当前时间 - 当前工序开始时间</span>
                </el-popover>
                {{scope.row.remaindays}} 天
              </div>
              <div v-else>0</div>
            </template>
          </el-table-column>
        </el-table>
        <!-- 分页 -->
        <el-pagination @current-change="handleFactoryChartDetailCurrentChange"
          :current-page="factoryChartDetail.queryInfo.currentPage" :page-sizes="[12]"
          :page-size="factoryChartDetail.queryInfo.pageSize" layout="prev,pager,next,jumper,sizes,total"
          :total="factoryChartDetail.total">
        </el-pagination>
      </el-dialog>

      <el-dialog :title="productFamilyChartDetail.title" :width="'95%'" :top="'10px'"
        :visible.sync="productFamilyChartDetail.dialogVisiable">
        <el-table v-loading="loading" v-loading.fullscreen.lock="loading" :element-loading-text="loadingText"
          element-loading-background="rgba(0,0,0,0.8)" :data="productFamilyChartDetail.dataList" stripe border>
          <el-table-column type="index" width="40px"></el-table-column>
          <el-table-column label="分厂" prop="factoryname" width="120" show-overflow-tooltip></el-table-column>
          <el-table-column label="订单号" prop="mfgordername" width="120" show-overflow-tooltip></el-table-column>
          <el-table-column label="机型" prop="familylistnames" width="100" show-overflow-tooltip>
          </el-table-column>
          <el-table-column label="零件图号" prop="productname" width="120" show-overflow-tooltip></el-table-column>
          <el-table-column label="零件名称" prop="productdescription" width="100" show-overflow-tooltip>
          </el-table-column>
          <el-table-column label="流水卡号" prop="containername" show-overflow-tooltip>
          </el-table-column>
          <el-table-column label="数量" prop="qty" width="60" show-overflow-tooltip></el-table-column>
          <el-table-column label="当前工序" prop="workflowstepname" width="100" show-overflow-tooltip>
          </el-table-column>
          <el-table-column label="主制工区" prop="fromworkcentername" width="100" show-overflow-tooltip>
          </el-table-column>
          <el-table-column label="计划员" prop="fullname" width="70" show-overflow-tooltip></el-table-column>
          <el-table-column label="开卡时间" prop="originalstartdate" width="100" :formatter="splitDate"></el-table-column>
          <el-table-column label="当前工序开始时间" prop="lastactivitydate" width="140" :formatter="splitDate">
          </el-table-column>
          <el-table-column label="停滞时间" prop="remaindays" width="100">
            <template slot-scope="scope">
              <div v-if="scope.row.remaindays > 0" style="color:red;">
                <el-popover placement="top-start" title="" width="200" trigger="hover" content="\n ">
                  <i class="el-icon-info" slot="reference"></i>
                  <span>停滞时间 = 系统当前时间 - 当前工序开始时间</span>
                </el-popover>
                {{scope.row.remaindays}} 天
              </div>
              <div v-else>0</div>
            </template>
          </el-table-column>
        </el-table>
        <!-- 分页 -->
        <el-pagination @current-change="handleProductFamilyChartDetailCurrentChange"
          :current-page="productFamilyChartDetail.queryInfo.currentPage" :page-sizes="[12]"
          :page-size="productFamilyChartDetail.queryInfo.pageSize" layout="prev,pager,next,jumper,sizes,total"
          :total="productFamilyChartDetail.total">
        </el-pagination>
      </el-dialog>
    </div>
  </div>
  <script src="../Scripts/echarts/echarts-5.4.0.min.js"></script>
  <script type="module">
    import { barOption, colorList } from '../Scripts/hooks/chartConfig.js'
    import { exportExcelData, fetchSuggestion } from '../Scripts/hooks/useCommonMethod.js'
    import { getProductFamily, getFactory } from '../Scripts/hooks/fetchAPI.js'
    import { prevWeek, thisWeek, nextWeek, prevMonth, thisMonth, nextMonth } from '../Scripts/hooks/useDateShortCut.js'
    import { splitDate } from '../Scripts/hooks/format.js'
    import Vue2BoardHeader from '../Scripts/components/Vue2BoardHeader.js'
    const app = new Vue({
      el: '#app',
      components: { Vue2BoardHeader },
      data: {
        splitDate,
        total: 0,
        loading: false,
        loadingText: '数据加载中...',
        queryInfo: {
          productfamilyname: '',
          factoryid: '',
          mfgordername: '',
          productname: '',
          containername: '',
          startdate: '',
          interval: 7,//停滞时间
          currentPage: 1,//当前页
          pageSize: 10//每页显示条数
        },
        dataList: [],
        factoryList: [],
        productfamilyList: [],
        factoryChartTitle: '各分厂停滞7天零件',
        factoryChartDetail: {
          dialogVisiable: false,
          queryInfo: { factoryname: '', currentPage: 1, pageSize: 12 },
          dataList: [], total: 0, title: ''
        },
        productfamilyChart: '各机型停滞7天零件',
        productFamilyChartDetail: {
          dialogVisiable: false,
          queryInfo: { productfamilyname: '', currentPage: 1, pageSize: 12 },
          dataList: [], total: 0, title: ''
        },
        // 表单验证
        rules: { interval: [{ required: true, message: '停滞时间不能为空', trigger: 'blur' }] },
        loadingConfig: { text: '数据查询中...', effect: 'whirling', maskColor: 'transparent', textColor: '#fff' },
        pickerOptions: { shortcuts: [prevWeek, thisWeek, nextWeek, prevMonth, thisMonth, nextMonth] }
      },
      methods: {
        // 查询订单号
        searchMfgorderAsync(value, callback) {
          fetchSuggestion({ actionName: 'getMfgordernameAsync', name: 'mfgordername', value, callback });
        },
        // 查询件号
        searchProductAsync(value, callback) {
          fetchSuggestion({ actionName: 'getProductnameAsync', name: 'productname', value, callback });
        },
        // 查询批次号
        searchContainerAsync(value, callback) {
          fetchSuggestion({ actionName: 'getContainernameAsync', name: 'containername', value, callback });
        },
        // 各分厂停滞零件统计--柱状图
        async getFactoryChartData() {
          const dom = document.getElementById("factoryChart");
          echarts.dispose(dom);
          let chart = echarts.init(dom);
          chart.showLoading(this.loadingConfig);

          const { data: { data, meta, total } } = await axios.post('../handler/board/ContainerRemainDashBoard.ashx?action=getFactoryChartData', {
            type: 'getFactoryChartData',
            ...this.queryInfo
          })
          chart.hideLoading();
          if (meta.status === 500) { return this.$message.error(meta.msg); }
          if (data.length === 0) { return; }

          echarts.dispose(dom);
          chart = echarts.init(dom);

          let arrFactory = [], arrRemainDays = [];
          for (const i of data) {
            arrFactory.push(i.factoryname);
            arrRemainDays.push(i.remaindays);
          }

          let option = barOption();
          option.legend.data = ['数量'];//设置图例文字
          option.xAxis.data = arrFactory;
          option.yAxis[1].show = false;

          option.series[0] = _.merge(option.series[0], {
            name: '数量', data: arrRemainDays,
            label: { color: colorList.blue.color },
            itemStyle: { color: { colorStops: colorList.blue.colorStops } }
          });

          chart.setOption(option);
          // 解决边框组件宽高异常
          setTimeout(() => { this.$refs.factoryChart.initWH(); chart.resize(); }, 300);

          chart.on('click', (params) => {
            if (params.value == 0) { return; }
            this.factoryChartDetail.queryInfo.currentPage = 1;
            this.factoryChartDetail.queryInfo.factoryname = params.name;
            this.factoryChartDetail.title = `【${params.name}】停滞 ${this.queryInfo.interval}+ 天零件明细`
            this.factoryChartDetail.dialogVisiable = true
            this.getFactoryChartDetail();
          })
        },
        // 各分厂停滞零件统计--柱状图明细
        async getFactoryChartDetail() {
          this.loading = true;
          this.loadingText = '数据加载中...';
          const { data: { data, meta, total } } = await axios.post('../handler/board/ContainerRemainDashBoard.ashx?action=getFactoryChartDetail', {
            type: 'getFactoryChartDetail',
            ...this.queryInfo,
            ...this.factoryChartDetail.queryInfo
          });
          this.loading = false;
          if (meta.status === 500) { return this.$message.error(meta.msg); }
          this.factoryChartDetail.dataList = data;
          this.factoryChartDetail.total = total;
        },
        // 各机型停滞零件统计--柱状图
        async getProductFamilyChartData() {
          const dom = document.getElementById("productfamilyChart");
          echarts.dispose(dom);
          let chart = echarts.init(dom);
          chart.showLoading(this.loadingConfig);

          const { data: { data, meta, total } } = await axios.post('../handler/board/ContainerRemainDashBoard.ashx?action=getProductFamilyChartData', {
            type: 'getProductFamilyChartData',
            ...this.queryInfo
          })
          chart.hideLoading();
          if (meta.status === 500) { return this.$message.error(meta.msg); }
          if (data.length === 0) { return; }

          echarts.dispose(dom);
          chart = echarts.init(dom);

          let arrProductFamily = [], arrRemainDays = [];
          for (const i of data) {
            arrProductFamily.push(i.familylistnames);
            arrRemainDays.push(i.remaindays);
          }

          let option = barOption({ showDataZoom: true, startValue: 0, endValue: 6 });
          option.legend.data = ['数量'];//设置图例文字
          option.xAxis.data = arrProductFamily;
          option.yAxis[1].show = false;

          option.series[0] = _.merge(option.series[0], {
            name: '数量', data: arrRemainDays,
            label: { color: colorList.blue.color },
            itemStyle: { color: { colorStops: colorList.blue.colorStops } }
          });

          chart.setOption(option);
          // 解决边框组件宽高异常
          setTimeout(() => { this.$refs.productfamilyChart.initWH(); chart.resize(); }, 300);

          chart.on('click', (params) => {
            if (params.value == 0) { return; }
            this.productFamilyChartDetail.queryInfo.currentPage = 1;
            this.productFamilyChartDetail.queryInfo.productfamilyname = params.name;
            this.productFamilyChartDetail.title = `【${params.name}】停滞 ${this.queryInfo.interval}+ 天零件明细`;
            this.productFamilyChartDetail.dialogVisiable = true;
            this.getProductFamilyChartDetail();
          })
        },
        // 各分厂停滞零件统计--柱状图明细
        async getProductFamilyChartDetail() {
          this.loading = true;
          this.loadingText = '数据加载中...';
          const { data: { data, meta, total } } = await axios.post('../handler/board/ContainerRemainDashBoard.ashx?action=getProductFamilyChartDetail', {
            type: 'getProductFamilyChartDetail',
            ...this.queryInfo,
            ...this.productFamilyChartDetail.queryInfo
          });
          this.loading = false;
          if (meta.status === 500) { return this.$message.error(meta.msg); }
          this.productFamilyChartDetail.dataList = data;
          this.productFamilyChartDetail.total = total;
        },
        // 停滞信息明细--查询
        async getContainerData() {
          this.loading = true;
          this.loadingText = '数据加载中...';
          const { data: { data, meta, total } } = await axios.post('../handler/board/ContainerRemainDashBoard.ashx?action=getContainerData', {
            type: 'getContainerData',
            ...this.queryInfo
          })
          this.loading = false;
          if (meta.status === 500) { return this.$message.error(meta.msg); }
          this.dataList = data;
          this.total = total;
          // 解决边框组件宽高异常
          setTimeout(() => { this.$refs.datagrid.initWH(); }, 300);
        },
        // 停滞信息明细--导出
        exportData() {
          const config = {
            url: '../handler/board/ContainerRemainDashBoard.ashx?action=exportData',
            data: { type: 'exportData', ...this.queryInfo }
          }
          exportExcelData(config, this);
        },
        // 查询按钮
        searchData() {
          this.$refs['queryInfoRef'].validate(async (valid) => {
            if (!valid) {
              return this.$message.error('必填项不能为空');
            } else {
              this.factoryChartTitle = `各分厂停滞${this.queryInfo.interval}天零件`;
              this.productfamilyChart = `各机型停滞${this.queryInfo.interval}天零件`;
              this.getContainerData();
              this.getFactoryChartData();
              this.getProductFamilyChartData();
            }
          })
        },
        handleCurrentChange(newPage) {
          this.queryInfo.currentPage = newPage;
          this.getContainerData();
        },
        handleSizeChange(newSize) {
          this.queryInfo.pageSize = newSize;
          this.getContainerData();
        },
        handleFactoryChartDetailCurrentChange(newPage) {
          this.factoryChartDetail.queryInfo.currentPage = newPage;
          this.getFactoryChartDetail();
        },
        handleProductFamilyChartDetailCurrentChange(newPage) {
          this.productFamilyChartDetail.queryInfo.currentPage = newPage;
          this.getProductFamilyChartDetail();
        }
      },
      async mounted() {
        this.factoryList = await getFactory();//查询分厂列表
        this.productfamilyList = await getProductFamily();//查询机型
        this.getContainerData();
        this.getFactoryChartData();
        this.getProductFamilyChartData();
      }
    })
  </script>
</body>

</html>